package com.ruoyi.web.controller.business;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WcChangePatentApplication;
import com.ruoyi.system.domain.WcChangePatentApplicationAncillary;
import com.ruoyi.system.domain.vo.business.*;
import com.ruoyi.system.service.IWcChangePatentApplicationAncillaryService;
import com.ruoyi.system.service.IWcChangePatentApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 剧本变更备案申请Controller
 *
 * @author ruoyi
 * @date 2024-02-28
 */
@Controller
@Api(tags = {"剧本变更备案申请"})
@RequestMapping("/system/wcChangePatentApplication")
public class WcChangePatentApplicationController extends BaseController {

    @Autowired
    private IWcChangePatentApplicationService service;

    @Autowired
    private IWcChangePatentApplicationAncillaryService ancillaryService;

    /**
     * 查询剧本变更备案申请列表
     */
    @ApiOperation("查询剧本变更备案申请列表")
    @PreAuthorize("@ss.hasPermi('system:changePatentApplication:list')")
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult<Page<WcChangePatentApplicationSelectListVO>> list(@RequestBody WcChangePatentApplicationSelectListDto dto) {
        if (dto.getStatus() != -1) {
            dto.setApprovalUserId(getUserId());
        }
        Page<WcChangePatentApplicationSelectListVO> list = service.list(dto);
        return success(list);
    }

    /**
     * 剧本变更备案申请详情
     */
    @ApiOperation("剧本变更备案申请详情")
    @PreAuthorize("@ss.hasPermi('system:changePatentApplication:detail')")
    @GetMapping("/edit/{id}")
    @ResponseBody
    public AjaxResult edit(@PathVariable("id") Long id) {
        WcChangePatentApplicationDetailVO vo = service.selectWcChangePatentApplicationDetailVOById(id);
        return success(vo);
    }

    /**
     * 修改保存剧本变更备案申请
     */
    @ApiOperation("修改剧本变更备案申请")
    @PreAuthorize("@ss.hasPermi('system:changePatentApplication:edit')")
    @Log(title = "剧本变更备案申请", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody WcChangePatentApplication wcChangePatentApplication) {
        return toAjax(service.updateWcChangePatentApplication(wcChangePatentApplication));
    }

    /**
     * 删除剧本变更备案申请
     */
    @ApiOperation("删除剧本变更备案申请")
    @PreAuthorize("@ss.hasPermi('system:changePatentApplication:remove')")
    @Log(title = "剧本变更备案申请", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id) {
        boolean b = service.removeById(id);
        //附件一块删除
        ancillaryService.remove(Wrappers.lambdaQuery(WcChangePatentApplicationAncillary.class).
                eq(WcChangePatentApplicationAncillary::getWcChangePatentApplicationId,id));
        return toAjax(b);
    }
}
